let App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    orderCount: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    //this.getUserActiveNUm();
    //console.log(this.data.userInfo);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    // 获取当前用户信息
    this.getUserDetail();
    //this.getUserActiveNUm();
  },

  // 统计个状态活动的数量
  getUserActiveNUm:function(){
    let _this = this;
    App._get('user.index/getUserActiveNUm', {}, function (result) {
      console.log(result);
      _this.setData(result.data);
    });
  },

  /**
   * 获取当前用户信息
   */
  getUserDetail: function() {
    let _this = this;
    App._get('user.index/detail', {}, function(result) {
      _this.setData(result.data);
    });
  },

  /**
   * 订单导航跳转
   */
  onTargetOrder(e) {
    // 记录formid
    App.saveFormId(e.detail.formId);
    let urls = {
      //all: '/pages/order/index?type=all',
      // payment: '/pages/order/index?type=payment',
      // received: '/pages/order/index?type=received',
      // refund: '/pages/order/refund/index',
      // init: '/pages/doing/user/index?type=userInit', //直接拼团
      // join: '/pages/doing/user/index?type=userJoin',
      // enough: '/pages/doing/user/index?type=userSelect',//自主拼团

      yue: '/pages/doing/user/index?type=yue',//约人
      beiyue: '/pages/doing/user/index?type=beiyue',//被约
      finish: '/pages/doing/user/index?type=userGather',//未付款
      pay: '/pages/doing/user/index?type=userPay',//已付款
    };
    // 转跳指定的页面
    wx.navigateTo({
      url: urls[e.currentTarget.dataset.type]
    })
  },

  /**
   * 菜单列表导航跳转
   */
  onTargetMenus(e) {
    // 记录formId
    App.saveFormId(e.detail.formId);
    console.log()
    if (e.currentTarget.dataset.url =='pages/dealer/index/index') {
      wx.switchTab({
        url: '/' + e.currentTarget.dataset.url
      })
    } else {
      wx.navigateTo({
        url: '/' + e.currentTarget.dataset.url
      })
    }
  },

  login:function(){
    // 跳转授权页面
    wx.navigateTo({
      url: "/pages/login/login"
    });
  },

  loginOut:function(){
    //console.log(111);
    let token = wx.getStorageSync('token');
    let _this= this;
    console.log(token);
    App._get('user/login_out', { token: token}, function (result) {
      //_this.setData(result);
      //console.log(result);

      _this.setData({
        userInfo: {},
        userInit_num:0,
        userSelect_num:0,
        userYue_num:0,
        userBeiyue_num:0,
        userGather_num:0,
        userPay_num:0
      });
      
    });
  },

})